package com.chinaisafe.demo.entity;

import java.io.Serial;

import com.chinaisafe.demo.vo.request.DemoTableReqVO;
import com.chinaisafe.demo.vo.response.DemoTableRespVO;
import com.chinaisafe.demo.dto.DemoTableDTO;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.chinaisafe.base.mybatisplus.entity.BaseEntity;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * DemoTable
 * Description：测试类实体类
 *
 * @author JiangZhaoYong
 * @date 2024-07-15 13:00:14
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("demo_table")
@Schema(name = "DemoTable", description = "测试类")
public class DemoTable extends BaseEntity {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "姓名")
    @TableField("`name`")
    private String name;

    @Schema(description = "年龄")
    @TableField("age")
    private Integer age;

    @Schema(description = "时间日期字段")
    @TableField("data_time_field")
    private LocalDateTime dataTimeField;

    @Schema(description = "日期字段")
    @TableField("data_field")
    private LocalDate dataField;

    @Schema(description = "时间字段")
    @TableField("time_field")
    private LocalTime timeField;

    /**
     * 将请求值对象装换为实体类
     *
     * @param reqVO 请求值对象
     * @return DemoTable
     * @author JiangZhaoYong
     * @date 2024-07-15 13:00:14
     */
    public static DemoTable convertFromReqVo(DemoTableReqVO reqVO) {
        DemoTable entity = new DemoTable();
        entity.setId(reqVO.getId());
        entity.setVersion(reqVO.getVersion());
        // 给实体对应的字段赋值 可根据实际业务删减
        entity.setName(reqVO.getName());
        entity.setAge(reqVO.getAge());
        entity.setDataTimeField(reqVO.getDataTimeField());
        entity.setDataField(reqVO.getDataField());
        entity.setTimeField(reqVO.getTimeField());
        return entity;
    }

    /**
     * 将实体类转换为响应值对象
     *
     * @return DemoTableRespVO
     * @author JiangZhaoYong
     * @date 2024-07-15 13:00:14
     */
    public DemoTableRespVO convertToRespVO() {
        DemoTableRespVO respVo = new DemoTableRespVO();
        respVo.setId(this.getId());
        respVo.setVersion(this.getVersion());
        // 给响应值对象对应的字段赋值 可根据实际业务删减
        respVo.setName(this.getName());
        respVo.setAge(this.getAge());
        respVo.setDataTimeField(this.getDataTimeField());
        respVo.setDataField(this.getDataField());
        respVo.setTimeField(this.getTimeField());
        return respVo;
    }

    /**
     * 将实体类转换为传输值对象
     *
     * @return DemoTableDTO
     * @author JiangZhaoYong
     * @date 2024-07-15 13:00:14
     */
    public DemoTableDTO convertToDTO() {
        DemoTableDTO dto = new DemoTableDTO();
        dto.setId(this.getId());
        // 给传输值对象对应的字段赋值 可根据实际业务删减
        dto.setName(this.getName());
        dto.setAge(this.getAge());
        dto.setDataTimeField(this.getDataTimeField());
        dto.setDataField(this.getDataField());
        dto.setTimeField(this.getTimeField());
        return dto;
    }
}
